(function (aopc) {
    aopc.addExpandPage(803, function (get) {
        const Common = get('UtilsCommon', 'Common');
        return {
            expandInit() {
                this.dataGridView1 = this.getProperty('dataGridView1');
            },
            setInit() {
                this.pageData.MeetingRoomId = this.visitUser.MeetingRoomId;
            },
            expandSetData({ rowData }) {
            },
            toNewMeetingEdit() {
                this.toPage('/bookMeetingEdit.html?MeetingId=' + Common.createGuid());
            },
            toMeetingEdit({ property }) {
                const { MeetingId, TimeStatus3, CreateUser } = property.rowData.data;
                let pageName = 'bookMeetingEdit.html';
                if (TimeStatus3 || CreateUser !== this.visitUser.UserId) pageName = "meetingSubjectList.html"
                this.toPage(`/${pageName}?MeetingId=${MeetingId}`);
            },
            setIsTemplate({ property }) {
                this.changeIsTemplate(property, 1);
            },
            cancelIsTemplate({ property }) {
                this.changeIsTemplate(property, 0);
            },
            deleteMeeting({ property }) {
                if (property.isLoading) return;
                const { data } = property.rowData;
                const { MeetingId, RowVersion } = data;

                if (property.isLoading) return;
                this.confirm('确定要删除当前会议吗', () => {
                    const { serviceInterface } = property;
                    const { serviceName, actionName } = serviceInterface;

                    const payload = { pathQuery: `(${MeetingId})?RowVersion=${RowVersion}` }

                    property.isLoading = true;
                    this.dispatchAction(serviceName, actionName, payload).then(res => {
                        property.isLoading = false;
                        if (res.isSuccess !== false) {
                            this.alertSuccess('删除成功！', () => {
                                data._isDelete = 1;
                                const row_view = property.getView().getView().getView().getView();
                                row_view.setIsVisible(false);
                            });
                        }
                    });
                });
            },
            copyMeeting({ property }) {
                if (property.isLoading) return;
                const { data } = property.rowData;
                const { MeetingId, RowVersion } = data;

                if (property.isLoading) return;
                this.confirm('确定要复制当前会议吗', () => {
                    const { serviceInterface } = property;
                    const { serviceName, actionName } = serviceInterface;

                    const payload = { Meeting: { MeetingId, RowVersion } }

                    property.isLoading = true;
                    this.dispatchAction(serviceName, actionName, payload).then(res => {
                        property.isLoading = false;
                        if (res.isSuccess !== false) {
                            this.alertSuccess('复制成功！', () => {
                                this.dataGridView1.refresh(1);
                            });
                        }
                    });
                });
            },
            changeIsTemplate(property, isTemplate) {
                if (property.isLoading) return;
                const { data } = property.rowData;
                const { MeetingId, RowVersion } = data

                const pathQuery = `(${MeetingId})`;

                const message = isTemplate ? "确定设为模板吗？" : '确定取消模板吗？';
                this.confirm(message, () => {
                    property.isLoading = true;
                    const { serviceName, actionName } = property.serviceInterface;

                    this.dispatchAction(serviceName, actionName, { pathQuery, Meeting: { IsTemplate: isTemplate, RowVersion } }).then(res => {
                        if (res.isSuccess === false) return;
                        else {
                            data.IsTemplate = isTemplate;
                            data.IsTemplate2 = 1 - isTemplate;
                            data.RowVersion = res.RowVersion;
                        }

                        const view = property.getView();
                        const [p1, p2, p3] = view.properties;
                        p1.defaultValue = data.IsTemplate;
                        p2.defaultValue = data.IsTemplate2;
                        p3.defaultValue = data.IsTemplate;
                        p1.refresh();
                        p2.refresh();
                        p3.refresh();

                        const row_content = view.getView().getView();

                        if (!property.IsTemplateName) property.IsTemplateName = this.getViewProperty(row_content, 'IsTemplateName');
                        property.IsTemplateName.setValue(isTemplate ? '模板' : '');

                        property.isLoading = false;
                    });
                });
            },
            successEndCallback({ property }) {
                const { data } = property.rowData;
                const { MeetingId } = data
                this.webSocket.send('endMeeting', { MeetingId });
            }
        }
    });
})(window.aopc);